package cn.wolfcode.crm.web.controller;

import cn.wolfcode.crm.domain.SystemDictionaryBill;
import cn.wolfcode.crm.service.ISystemDictionaryBillService;
import cn.wolfcode.crm.util.JsonResult;
import cn.wolfcode.crm.util.PermissionName;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping("systemDictionaryBill")
public class SystemDictionaryBillController {

    @Autowired
    private ISystemDictionaryBillService service;

    @RequiresPermissions("systemDictionary:save")
    @PermissionName("添加明细")
    @ResponseBody
    @RequestMapping("save")
    public JsonResult save(SystemDictionaryBill record)
    {
        JsonResult result = new JsonResult();
        try {
            service.insert(record);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("保存失败");
        }
        return result;
    }

    @RequiresPermissions("systemDictionary:edit")
    @PermissionName("编辑明细")
    @ResponseBody
    @RequestMapping("edit")
    public JsonResult edit(SystemDictionaryBill record)
    {
        JsonResult result = new JsonResult();
        try {
            service.updateByPrimaryKey(record);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("编辑失败");
        }
        return result;
    }

    @RequiresPermissions("systemDictionary:delete")
    @PermissionName("编辑删除")
    @ResponseBody
    @RequestMapping("delete")
    public JsonResult delete(Long id)
    {
        JsonResult result = new JsonResult();
        try {
            service.deleteByPrimaryKey(id);
        } catch (Exception e) {
            e.printStackTrace();
            result = new JsonResult("删除失败");
        }
        return result;
    }
}
